package com.service.good;

import com.dao.BaseDao;
import com.dao.good.GoodDao;
import com.dao.good.GoodDaoImpl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class GoodServiceImpl implements GoodService{

    private final GoodDao goodDao;
    public GoodServiceImpl(){
        goodDao = new GoodDaoImpl();
    }

    @Override
    public List<Object> getSearchGoodList(String goodName) {

        Connection connection = null;
        List<Object> goods = null;


        try {
            connection = BaseDao.getConnection();
            goods = goodDao.getSearchGoodList(connection, goodName);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }


        return goods;
    }

    @Override
    public List<Object> getUserGoodList(int userId) {
        Connection connection = null;
        List<Object> good = null;

        try {
            connection = BaseDao.getConnection();
            good = goodDao.getUserGoodList(connection, userId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return good;
    }

    @Override
    public int UserGoodListDel(int goodId) {
        Connection connection = null;
        int flag = 0;
        connection = BaseDao.getConnection();
        try {
            flag = goodDao.UserGoodListDel(connection,goodId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

    @Override
    public int GoodAdd(int userId, String goodName, String goodAddress, String goodExplain) {
        Connection connection = null;
        int flag = 0;
        connection = BaseDao.getConnection();
        try {
            flag = goodDao.GoodAdd(connection,userId,goodName,goodAddress,goodExplain);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return flag;
    }

}
